import * as Router from "koa-router";
import * as index from "./controller/index";
import * as wechat from "./controller/wechat";
import * as auth from "./controller/auth";
import * as community from "./controller/community";
import * as upload from "./controller/upload";
import * as topic from "./controller/topic";
import * as user from "./controller/user";

export const router = new Router();
router
    .prefix('/api')
    .get('/', index.hello)
    .all('/wechat', wechat.reply)
    .get('/wechat/jsconfig', wechat.getJsConfig)
    .get('/auth/loginFromCommunity/:community_id', auth.loginFromCommunity)
    .get('/auth/login', auth.login)
    .get('/auth/wechatQrcodeUrl', auth.getWechatQrcodeUrl)
    .use(auth.check)
    .get('/auth/loginUrl', auth.getLoginUrl)
    .get('/user/:openid', user.findOneByOpenid)
    .post('/user/:openid', upload.userHeadimg, user.update)

    .get('/community/countByName', community.countByName)
    .get('/community/:id', community.findOneById)
    .post('/community', upload.communityHeadimg, community.create)
    .post('/community/:id/uploadCover', upload.communityCover, community.updateCoverurl)
    .post('/community/:id/uploadHeadimg', upload.communityHeadimg, community.updateHeadimgurl)
    .get('/communityByOpenid', community.findByOpenid)
    .put('/community/:id/wechat', community.updateWechat)
    .put('/community/:id', community.update)
    .post('/joinCommunity/:id', community.addUser)
    .post('/quitCommunity/:id', community.deleteUser)
    .get('/communityByName', community.findByName)
    .delete('/community/:id', community.remove)

    .post('/topic', upload.topicPics, topic.create)
    .get('/topicByCommunityId', topic.findByCommunityId)
    .post('/topic/:id/liker/:liker_id', topic.createLiker)
    .delete('/topic/:id/liker/:liker_id', topic.removeLiker)
    .put('/topic/:id/receive_notice', topic.createReceiveNotice)

    .post('/topic/:id/comment', topic.createComment)
    .get('/topic/:id/comment', topic.findCommentsByTopicId)
    .post('/comment/:comment_id/liker/:liker_id', topic.createCommentLiker)
    .delete('/comment/:comment_id/liker/:liker_id', topic.removeCommentLiker)
